package com.hoshiicloud.registered.controller;

import cn.hutool.core.bean.BeanUtil;
import com.hoshiicloud.common.aop.Logable;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.common.utils.SMSCodeUtil;
import com.hoshiicloud.common.validate.annotations.Mobile;
import com.hoshiicloud.registered.feign.VericenterService;
import com.hoshiicloud.registered.service.RegisterdUsersService;
import com.hoshiicloud.user.param.company.CompanyAddParam;
import com.hoshiicloud.user.param.company.CompanyRegisteredParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户注册
 *
 * @author MarkerCCC
 * @date 2019/9/10 - 15:42
 */
@Slf4j
@RestController
@RequestMapping("/registered/registeredController")
@Api(value = "用户注册", tags = {"用户注册"})
public class RegisteredUsersController {

    @Autowired
    private RegisterdUsersService registerdUsersService;

    /**
     * 获取验证码
     */
    @GetMapping("/getVerificationCode")
    @Logable(authName = "用户注册-发送短信验证码")
    @ApiOperation(value = "发送短信验证码", notes = "发送短信验证码", httpMethod = "GET", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号码", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "areaCode", value = "地区编号", dataType = "String", paramType = "query", required = true)
    })
    public Response<String> getVerificationCode(@RequestParam("mobile") @Mobile String mobile, @RequestParam("areaCode") String areaCode) {
        String areaMobile = areaCode + mobile;
        return registerdUsersService.getVerificationCode(areaMobile);
    }

    /**
     * 租户注册
     */
    @PostMapping("/theTenantVerification")
    @Logable(authName = "用户注册-租户注册")
    @ApiOperation(value = "租户注册", notes = "租户注册", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Response theTenantVerification(@RequestBody @Valid CompanyRegisteredParam companyRegisteredParam) {
        return registerdUsersService.theTenantVerification(companyRegisteredParam);
    }
}
